-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve CodeSyntaxHighlight object #268
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #268 +/- ##
==========================================
- Coverage 87.12% 87.01% -0.12%
==========================================
Files 46 46
Lines 3441 3465 +24
==========================================
+ Hits 2998 3015 +17
- Misses 443 450 +7 ☔ View full report in Codecov by Sentry. |
I assume the two failing napari tests are unrelated, but @Czaki could you confirm? |
Yes. It is a recent contribution to napari. Maybe we should think to also easy skip test marked as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
"Consolas", | ||
"Andale Mono", | ||
"Source Code Pro", | ||
"monospace", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it may be worth to and Ubuntu Mono
- the default mono font on Ubuntu system.
def palette(self) -> QPalette: ... | ||
def setPalette(self, palette: QPalette) -> None: ... | ||
|
||
KnownStyle: TypeAlias = Literal[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any plan for trace pigments style updates (ex compare pygments.styles.STYLES content witrh this annotation in tests) or just wait for issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no plan... but I'll mention that the type hint here is actually:
theme: KnownStyle | str = "default",
which means that users will get the autocomplete suggestions, but it's not an error to enter something that is not in the KnownStyle list. So the only "issue" we might see is that someone didn't get a nice autocomplete hint :) (but mypy won't mind)
text_char_format.setForeground(QColor(f"#{color}")) | ||
if bgcolor := style.get("bgcolor"): | ||
text_char_format.setBackground(QColor(bgcolor)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why one with hash, and the other without?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! it was already that way (on main):
superqt/src/superqt/utils/_code_syntax_highlight.py
Lines 20 to 24 in 4da5ac2
if style.get("color"): | |
text_char_format.setForeground(QtGui.QColor(f"#{style['color']}")) | |
if style.get("bgcolor"): | |
text_char_format.setBackground(QtGui.QColor(style["bgcolor"])) |
you wrote that ... do you recall any reason for it?
i do use https://github.com/pyvista/setup-headless-display-action ... which replaces all three of the only thing I think they don't use is
that would be useful. some sort of mark rather than a local skip. will find some workaround for now. did you also have to change your CI setup in napari when that change went in? I don't remember |
Yes. It is required to propagate GUI events.
We have added |
TIL. Thanks Added it to setup headless action in pyvista/setup-headless-display-action#25 (and that fixes it here too) |
This PR improves a number of things and fixes some slight issues with
CodeSyntaxHighlight
:KnownStyle
for IDE suggestions of valid pygments namesget_text_char_format
was always clobbering whatever I did. Furthermore, it wasn't successfully applying "Monospace", instead I get:WARNING: Populating font family aliases took 75 ms. Replace uses of missing font family "Monospace" with one that exists to avoid this cost.
. So this adds a full font family tree that should work on any system, and it only applies it if the style explicitly sets the "mono" flag. This means that most users will now need to set Monospace themselves (but since it already wasn't working on, macos for example, this is probably a good thing).document()
, simplifying the usage, and also allowing allowing us to automatically set the background color on objects that support setPalette.setTheme
andsetLanguage
methods that allow you to change the style on an existing formatter, including updating the background color on supported objects.